#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline LL read()
{
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
LL k,l,r,ans;
LL cal(LL x)
{
	LL ret=0;
	while(x)
	{
		ret+=(x%10)*(x%10);
		x/=10;
	}
	return ret;
}
int main()
{
	k=read();l=read();r=read();
	for(LL i=0;i<=min(1458LL,r/k);++i)
	{
		if(i*k<l)continue;
		if(cal(i*k)==i)++ans;
	}
	printf("%lld\n",ans);
	return 0;
}
